package oop.day03;

public class RefArrayDemo
{
    public static void main(String[] args)
    {
        /*
        // 声明Dog类型的数组dogs  包含3个元素 每个元素都是Dog型，默认值为null
        Dog[] dogs = new Dog[3];
        // 声明Fish类型的数组fishes 包含3个元素，每个元素都是Fish类型，默认值为null
        Fish[] fishes = new Fish[3];
        // 声明Chick类型的数组chicks 包含3个元素，每个元素都是Chick类型 默认为null
        Chick[]  chicks = new Chick[3];

        System.out.println(chicks[1]);

        for (int i = 0; i < chicks.length; i++)
        {
            chicks[i] = new Chick("a",3,"red");
        }
        System.out.println(chicks[1]);    // 直接输出地址
        System.out.println(chicks[1].age);

        Dog[] dogs1 = new Dog[3];
        dogs1[0] = new Dog("a",1,"c");
        dogs1[1] = new Dog("b",1,"d");
        dogs1[2] = new Dog("c",2,"r");

        Fish[] fish1 = new Fish[3];
        fish1[0] = new Fish("fa",2,"r");
        fish1[1] = new Fish("b",2,"rr");
        fish1[2] = new Fish("fc",3,"rrr");

        Chick[] chicks1 = new Chick[3];
        chicks1[0] = new Chick("c1",2,"g");
        chicks1[1] = new Chick("c2",2,"gg");
        chicks1[2] = new Chick("c3",1,"gggg");

        for (int i = 0; i < dogs1.length; i++)
        {
            System.out.println(dogs1[i].color);

        }
        */



        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("a",1,"r");
        dogs[1] = new Dog("b",1,"rr");
        dogs[2] = new Dog("c",1,"rrr");

        System.out.println(dogs.length);
        System.out.println(dogs[1].name);
        dogs[1].swim();
        dogs[1].eat();



        Fish[] fish = new Fish[3];
        for (int i = 0; i < fish.length; i++)
        {
            fish[i] = new Fish("a",1,"cc");
        }
        for (int i = 0; i < fish.length; i++)
        {
            Fish fish1 = fish[i];
            System.out.println(fish1.age);
            System.out.println(fish1.name);
            fish1.eat();
            fish1.swim();
            fish1.drink();
        }

        Chick[] chicks = new Chick[3];
        for (int i = 0; i < chicks.length; i++)
        {
            Chick chick = chicks[i];
            chick = new Chick("a",1,"c");
            System.out.println(chick.age);
        }

        for (Chick c: chicks)
        {
            System.out.println(c.name);
            System.out.println(c.age);
        }

    }
}
